Skip to content

feat(transport): add opt-in bounded upstream retry advice - #27

Merged
ALikesToCode merged 1 commit into
integrate/gateway-waves-1-2from
feat/retry-advice
Oct 9, 2026
Merged

ALikesToCode merged 1 commit into
integrate/gateway-waves-1-2from
feat/retry-advice

Conversation

@ALikesToCode

Copy link
Copy Markdown
Owner

Summary

Adds bounded parsing of upstream retry and reset hints behind UPSTREAM_RETRY_AFTER_ADVICE_ENABLED, which defaults to false. While the flag is off, retries, waits, headers, bodies and free-pool cooldown timing are unchanged.

  • services/retry_advice.py parses Retry-After (seconds or HTTP-date), X-RateLimit-Reset, X-RateLimit-Reset-Requests/-Tokens and the Anthropic reset headers into immutable local advice. Malformed, stale and non-finite values are ignored.
  • Advice is clamped by UPSTREAM_RETRY_AFTER_MAX_SECONDS (default 3600, at most 7 days). Upstream headers are never rewritten.
  • services/managed_dispatch.py holds the managed retry scheduling that proxy_service.py previously repeated three times:
    • With the flag off, it does exactly what the old code did.
    • With it on, an allowed retry waits for the longer of the existing backoff and the advice.
    • A retry is skipped if that wait would pass the request's cascade deadline, and the original upstream response is returned instead.
  • Parsing advice never grants a retry. Ambiguous POSTs and streams gain no retry. With the flag on, a timeout-body retry also requires a safe method or an Idempotency-Key.
  • Free-pool retry_seconds uses the same bounded parser while enabled.

Details are in docs/retry-advice.md.

Shared registrations

  • Added UPSTREAM_RETRY_AFTER_ADVICE_ENABLED and UPSTREAM_RETRY_AFTER_MAX_SECONDS to the Container env keys.

Tests

  • tests/test_retry_advice.py: new. It includes registered-path tests for raw NanoGPT errors and Groq retries with the flag off and on.
  • Full Python suite: 3,240 passed. ruff, mypy and bandit are clean.
  • npm run test:worker: 1,227 passed. cf:migrations:check, test:deploy, free routes, client headers and the wrangler deploy --dry-run bundle all pass.
  • tests/test_frontend_build.mjs fails locally because @tailwindcss/cli is not installed. It fails the same way on main.

This is part of Wave 3. It is based on the Wave 2 integration branch (#25), and the Wave 3 integration PR adds the README line.

UPSTREAM_RETRY_AFTER_ADVICE_ENABLED (default off) parses Retry-After and documented reset headers into bounded local advice. An allowed managed retry then waits for the longer of the existing backoff and the advice, and is skipped when the wait would pass the request deadline. Parsing never grants a retry, and upstream headers are never rewritten. The managed retry scheduling moves into services/managed_dispatch.py and behaves exactly as before while the flag is off.
@coderabbitai

coderabbitai Bot commented Oct 8, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aeee0e04-0a23-485a-9b74-b5118613acf0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T21:48:33.796875Z aa62d68 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
multillm-proxy aa62d68 Oct 08 2026, 09:47 PM

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: aa62d6816d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

def retry_seconds(headers, now: float, default: int = 60) -> int:
settings = retry_advice_settings()
if settings.enabled:
advice = parse_retry_advice(headers, now=now, max_seconds=settings.max_seconds)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pass the actual upstream status into advice parsing

When advice is enabled, this call omits status_code, so parse_retry_advice classifies every free-route outcome as its default 429. The callers in routes/free_routes.py also use retry_seconds for 401/403/404 and other failures; consequently, a Retry-After on an authentication or caller error is accepted and can block a provider or model for up to the configured maximum, even though the parser explicitly rejects advice for those statuses. Add a status parameter and pass the available upstream status so these responses use the fallback cooldown instead.

Useful? React with 👍 / 👎.

@ALikesToCode
ALikesToCode merged commit 30f8c89 into integrate/gateway-waves-1-2 Oct 9, 2026
5 of 7 checks passed
@ALikesToCode
ALikesToCode deleted the feat/retry-advice branch October 26, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant